package com.xmhmyh.generalframework.project.systool.conversion;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xmhmyh.generalframework.project.systool.entity.QuartzJob;
import com.xmhmyh.generalframework.project.systool.vo.QuartzJobVO;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: 周哲轩
 * QuartzJob - > QuartzJobVO
 * @time: 2020/8/11 16.30
 */
public class QuartzJob2QuartzJobVOConversion {
    public static QuartzJobVO conversion(QuartzJob quartzJob) {
        QuartzJobVO quartzJobVO = QuartzJobVO.builder()
                .id(quartzJob.getId())
                .name(quartzJob.getName())
                .groupName(quartzJob.getGroupName())
                .beanName(quartzJob.getBeanName())
                .memo(quartzJob.getMemo())
                .cronExpression(quartzJob.getCronExpression())
                .status(quartzJob.getStatus())
                .build();
        return quartzJobVO;
    }

    public static List<QuartzJobVO> conversion(List<QuartzJob> quartzJobList) {
        return quartzJobList.stream().map(quartzJob -> {
            return conversion(quartzJob);
        }).collect(Collectors.toList());
    }
    public static IPage<QuartzJobVO> conversion(IPage<QuartzJob> quartzJobIPage){
        IPage<QuartzJobVO> page = new Page<>();
        page.setCurrent(quartzJobIPage.getCurrent());
        page.setPages(quartzJobIPage.getPages());
        page.setSize(quartzJobIPage.getSize());
        page.setTotal(quartzJobIPage.getTotal());
        page.setRecords(conversion(quartzJobIPage.getRecords()));
        return page;
    }
}
